/*  
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coverter;

import entities.Persona;
import entities.Responsable;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Agapo
 */
@FacesConverter("responsableConverter")
public class ResponsableConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Responsable r = new Responsable();
        Persona p = new Persona();
        String cad[] = value.split("__");
        p.setIdPersona(Integer.parseInt(cad[0]));
        p.setApPat(cad[1]);
        p.setApMat(cad[2]);
        p.setNombre(cad[3]);
        r.setIdResponsable(Integer.parseInt(cad[4]));
        r.setIdPersona(p);
        return r;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Responsable r = (Responsable) value;
        Persona p = r.getIdPersona();
        String cad = p.getIdPersona() + "__" + p.getApPat() + "__" + p.getApMat() + "__" + p.getNombre() + "__" + r.getIdResponsable();
        return cad;
    }
}
